package dk.itu.samd.group2.tagapastryClient;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class DeliciousData 
{
	// Based on delicious data
	public static final int COUNT_NEWS = 3051811;
	public static final int COUNT_MEDIA = 236177;
	public static final int COUNT_MUSIC = 5105542;
	public static final int COUNT_VIDEO = 325606;
	public static final int COUNT_SOFTWARE = 199263;
	public static final int COUNT_BLOG = 7383522;
	public static final int COUNT_PHOTOGRAPHY = 208522;
	public static final int COUNT_WEB2 = 4898861;
	
	public static final String[] tags = {"News","Media","Music","Video","Software","Blog","Photography","Web 2.0"};
	public static final String[] types = {"URLS"};
	
	public static final String[] newsUrls = {"news.com",
		"newsa.com","newsb.com","newsc.com","newsd.com",
		"bbc.co.uk","nytimes.com","yahoo.com","cnn.com"};
	
	
	private int count;
	private String tagName;
	private ArrayList<DeliciousData> ddata;
	private final String FILE_PATH = "taginfo.csv";
	
	public DeliciousData() {
		
	}
	
	public DeliciousData(int count, String tagName) {
		this.count = count;
		this.tagName = tagName;
	}
	
	private int getCount() {
		return this.count;
	}
	
	public int getCount(int i) {
		return this.ddata.get(i).getCount();
	}
	
	private String getTagName() {
		return this.tagName;
	}
	
	public String getTagName(int i) {
		return this.ddata.get(i).getTagName();
	}
	
	public ArrayList<DeliciousData> getTagInfo() {
		if(this.ddata == null || this.ddata.size() == 0) {
			System.out.println("Loading tag info...");
			this.importData(FILE_PATH);
		}
		
		return this.ddata;
	}
	
	private void importData(String fileName) {
		try {
			FileReader fr = new FileReader(fileName);
			BufferedReader br = new BufferedReader(fr);
			
			String line = "";
			ddata = new ArrayList<DeliciousData>();
			while(true) {
				line = br.readLine();
				if(line == null) break;
				
				String[] tmp = line.split(";");
				ddata.add(new DeliciousData(Integer.valueOf(tmp[1]), tmp[0]));
			}
		}
		catch(IOException ioex) {
			ioex.printStackTrace();
		}
	}
	
	public String toString() {
		return String.format("%d %s",count,tagName);
	}
}
